package com.example.bugdroid;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class Transmitter extends Activity {
	TextView status;
	Button connectionButton, sendButton;
	EditText sendMessage;

	BluetoothAdapter btAdapter;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.transmitter);
		init();
		initSetters();
		if (!btAdapter.isEnabled()) {
            Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
            startActivityForResult(enableIntent, 3);
        // Otherwise, setup the chat session
        } else {
            Toast.makeText(getApplicationContext(), "connection enable", Toast.LENGTH_SHORT).show();
        }
	}

	public void init() {
		/* TextView */
		status = (TextView) findViewById(R.id.transmitter_status);
		/* Button */
		connectionButton = (Button) findViewById(R.id.transmitter_connect_button);
		sendButton = (Button) findViewById(R.id.transmitter_send_button);
		/* EditText */
		sendMessage = (EditText) findViewById(R.id.transmitter_send);
		
		btAdapter = BluetoothAdapter.getDefaultAdapter();
		if (btAdapter == null) {
            Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
            finish();
            return;
        }
	}

	public void initSetters() {
		/* Button */
		
		connectionButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				btAdapter.startDiscovery();
			}
		});
		
		sendButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				
			}
		});
		
		
	}
}
